package com.bx.implatform.portal.utils;

import com.bx.implatform.util.BaseExternalApiService;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class PortalExternalApiService extends BaseExternalApiService {

    public PortalExternalApiService(@Qualifier("portalRestTemplate") RestTemplate restTemplate) {
        super(restTemplate);
    }



    // GET 请求（参数拼接在 URL 上）
    public <T> T get(String url, Class<T> responseType, Object... uriVariables) {
        // 如果外部系统要求 GET 请求的签名参数放在 URL 上，可以在这里处理
        return restTemplate.getForObject(url, responseType, uriVariables);
    }

    // POST 请求（参数放在请求体）
    public <T> T post(String url, Object requestBody, Class<T> responseType) {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);

        HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody, headers);

        return restTemplate.postForObject(url, requestEntity, responseType);
    }
}